package hu.elte.inf.holiuml.model;

import hu.elte.inf.holiuml.coordgeom.LineSegment;

import java.awt.Graphics;
import java.util.Vector;

/**
 * @author Csaba Hoch
 */
public class ConnectionEdge extends Edge {
	
	private Connection connection;
	private ObjectNode nodeBegin = null;
	private ObjectNode nodeEnd = null;

	public ConnectionEdge() {
	}

	public void setConnection(Connection connection) {
		this.connection = connection;
	}

	public Connection getConnection() {
		return connection;
	}

	@Override
	public void draw(Graphics g) {
		LineSegment ls = getLineSegment();
		if (ls != null) {
			g.setColor(java.awt.Color.BLACK);
			ls.draw(g);
		}
	}

	@Override
	public Node getNodeBegin() {
		return nodeBegin;
	}

	@Override
	public Node getNodeEnd() {
		return nodeEnd;
	}

	@Override
	public void setNodeBegin(Node node) {
		nodeBegin = (ObjectNode)node;

	}

	@Override
	public void setNodeEnd(Node node) {
		nodeEnd = (ObjectNode)node;
	}

	@Override
	public Vector<String> getTextVector() {
		Vector<String> v = new Vector<String>();
		if (connection != null) {
			Relation relation = connection.getRelation();
			if (relation != null) {
				v.add(relation.getRoleBegin());
				v.add(relation.getMultiBegin());
				v.add(relation.getName());
				v.add("operation()"); // TODO add the real operation
				v.add(relation.getRoleEnd());
				v.add(relation.getMultiEnd());
				return v;
			} else {
				return null;
			}
		} else {
			return null;
		}
	}
}